package com.hefei.garden.pojo;

import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.util.Objects;

/**
 * @author devil
 */
public class KafkaBaseDto {

    @NotNull
    private String topic;
    @NotNull
    private String groupId;
    @Null
    private int partitionId;

    public KafkaBaseDto(String topic, String groupId, int partitionId) {
        this.topic = topic;
        this.groupId = groupId;
        this.partitionId = partitionId;
    }

    public String getTopic() {
        return topic.trim();
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public String getGroupId() {
        return groupId.trim();
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public int getPartitionId() {
        return partitionId;
    }

    public void setPartitionId(int partitionId) {
        this.partitionId = partitionId;
    }

    public String getUniqueKey() {
        return topic + ":" + groupId + ":" + partitionId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(topic, groupId);
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof KafkaBaseDto)) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        KafkaBaseDto kafkaBaseDto = (KafkaBaseDto) obj;
        return StringUtils.equals(topic, kafkaBaseDto.getTopic()) && StringUtils.equals(groupId, kafkaBaseDto.getGroupId());
    }

}
